package ewms.utils;

import cn.hutool.core.date.DateUtil;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Date;

/**
 * 工具类
 */
public class EwmsUtils {

	private EwmsUtils() {
	}

	/**
	 * 处理选择的日期：给日期加上时间
	 *
	 * @param selectDate
	 * @param time
	 * @return
	 */
	public static Date handleSelectDate(Date selectDate, LocalTime time) {
		LocalDateTime localDateTime = DateUtil.toLocalDateTime(selectDate);
		LocalDate targetLocalDate = localDateTime.toLocalDate();
		LocalDateTime now = LocalDateTime.now();
		LocalDate myLocalDate = now.toLocalDate();
		LocalDateTime tempDateTime = null;
		if (targetLocalDate.compareTo(myLocalDate) == 0) {
			tempDateTime = now;
		} else {
			tempDateTime = targetLocalDate.atTime(time);
		}
		return Date.from(DateUtil.toInstant(tempDateTime));
	}


	/**
	 * 处理选择的日期：给日期加上时间
	 *
	 * @param selectDate
	 * @return
	 */
	public static Date handleSelectDate(Date selectDate) {
		LocalTime time = LocalTime.of(23, 57, 57);
		return handleSelectDate(selectDate, time);
	}

}
